#include"Date.h"

bool IsLeapYear(int y)
{
	return (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
}

int monthdays(int y, int m)
{
	static int a[13] = { 31,31,28,31,30,31,30,31,31,30,31,30,31 };
	if (m == 2 && IsLeapYear(y))
	{
		return 29;
	}
	else
		return a[m];
}

int isLeapYear(int y)
{
	if (IsLeapYear(y))
		return 366;
	else
		return 365;
}

Date::Date(int year, int month, int day)
{
	assert(year >= 1 && (month <= 12 && month >= 0) && (day >= 1 && day <= monthdays(year, month)));
	_year = year; _month = month; _day = day;
}

Date& Date:: operator=(const Date& d)
{
	if (this != &d)
	{
		_year = d._year; _month = d._month; _day = d._day;
	}
	return *this;
}

void Date::print()const
{
	cout << _year << "-" << _month << "-" << _day << endl;
}

bool Date::operator>=(const Date& d)const
{
	if ((_year > d._year)
		|| (_year == d._year && _month > d._month)
		|| (_year == d._year && _month == d._month && _day >= d._day))
	{
		return true;
	}
	return false;
}

ostream& operator<<(ostream& out, const Date& d)
{
	out << d._year << "-" << d._month << "-" << d._day  << endl;
	d.print();
	return out;
}

istream& operator>>(istream& in, Date& d)
{
	scanf("%d %d %d", &d._year, &d._month, &d._day);
	assert(d._year >= 1 && (d._month <= 12 && d._month >= 0) && (d._day >= 1 && d._day <= monthdays(d._year, d._month)));
	return in;
}

